//
//  PubulicNavSerachView.m
//  OnionHome
//
//  Created by fengjie on 2019/10/21.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "PubulicNavSerachView.h"

@interface PubulicNavSerachView ()

@end

@implementation PubulicNavSerachView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createUI];
    }
    return self;
}
-(void)createUI{

    UIView * bgView = UIView.new;
    
    bgView.backgroundColor = UIColorFromRGB(0xF5F7F5);
    ViewRadius(bgView, 4);
    
    UIImageView * leftImage = [[UIImageView alloc] initWithImage:IMAGE_NAMED(@"ic_nav_search")];
    
    [self addSubview:self.backBtn];
    [self addSubview:bgView];
    
    [self.backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.centerY.mas_equalTo(0);
        make.width.mas_equalTo(25);
    }];
    
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(0);
        make.left.mas_equalTo(self.backBtn.mas_right).offset(16);
        make.right.mas_equalTo(-8);
    }];
    
    [bgView addSubview:leftImage];
    [bgView addSubview:self.serachField];
    
    
    [leftImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.left.mas_equalTo(8);
        make.width.height.mas_equalTo(20);
    }];
    
    [self.serachField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.left.mas_equalTo(leftImage.mas_right).offset(4);
        make.top.bottom.right.mas_equalTo(0);
        make.height.mas_equalTo(30);
    }];
    
}
-(CGSize)intrinsicContentSize{
    return UILayoutFittingExpandedSize;
}
-(UIButton*)backBtn{
    if(!_backBtn){
        _backBtn=[UIButton new];
        [_backBtn setImage:IMAGE_NAMED(@"back") forState:UIControlStateNormal];
        [_backBtn sizeToFit];
    }
    return _backBtn;
}
#pragma mark ---懒加载
-(UITextField*)serachField{
    if(!_serachField){
        _serachField=[UITextField new];
        _serachField.placeholder = @"搜索用户名";
        _serachField.placeholderColor = UIColorFromRGB(0x959E97);
        _serachField.placeholderFont = PingFangSC_Light(14);
    }
    return _serachField;
}

@end
